	#include("/common/include/include.html")
<div class="admin-main">
	<div class="site-block-full navi-left" style="top: 0px;">
		<fieldset><legend>所有功能</legend>
			<ul id="menuTree"></ul>
		</fieldset>
	</div>
	<div class = "selecterBtnDiv">
		<a href="javascript:;" class="layui-btn layui-btn-small" onclick="selectOneOperate()">
			<i class="layui-icon">&#xe608;</i> 确定
		</a>
	</div>
</div>
<script>
 	var id = '#(id)';//角色id
	layui.config({
		  base: ctx+'/common/js/'
	}).use(['tree2','ajax','paging'], function(){
			 ajax = layui.ajax;
			 tree2 = layui.tree2;
			 paging = layui.paging();
			 refresh();
	});
	function refresh(){
		initTree();
	}
	//初始化左侧菜单树
	function initTree(){
		$("#menuTree").html("")
		var d = ajax.ajaxFunc(ctx+"/admin/operate/getAllOperatePermisstion",{"id":id},"json",null);
		layui.tree2({
		    elem: '#menuTree' //传入元素选择器
		    ,check: 'checkbox' //勾选风格
			,drag: true//点击每一项时是否生成提示信息
		    ,nodes: d.data
		    ,click: function(node){
		    	
		    }  
		});
	}
	//选择一个功能
	function selectOneOperate(){
		var checkedList = $("#menuTree").find("input:checked");
		var data = [];
		$.each(checkedList,function(i,d){
			var oid = $(d).val();
			if(oid){
				data.push(oid);
			}
			
		});
		var r = ajax.ajaxFunc(ctx+"/admin/role/addRolePermisstion",{"data":data.join(","),"roleid":id},"json",null);
		if(r.success){
			parent.layer.closeAll();
			parent.layer.alert(r.message);
		}
	}
</script>